package basic.thread.again;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**自己的可重入锁
 * @author bingo
 * @create 2018-02-28 14:37
 **/
public class MyLock2 implements Lock {

    private boolean isLocked = false;

    @Override
    public synchronized void lock() {

        while (isLocked){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
             isLocked=true;
    }

    @Override
    public void lockInterruptibly() throws InterruptedException {

    }

    @Override
    public boolean tryLock() {
        return false;
    }

    @Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
        return false;
    }

    @Override
    public synchronized void unlock() {
        notify();
        isLocked=false;

        System.out.println("解锁");

    }

    @Override
    public Condition newCondition() {
        return null;
    }
}
